﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;

namespace APPFrameworkStudy.Repository
{
    public interface IDataContext : IDisposable
    {
        //获取T对象的数据映射器实例
        IDataMapper<T> GetDataMapper<T>() where T : class, new();
        //CRUD服务
        bool Create<T>(T item) where T : class, new();
        bool Delete<T>(T item) where T : class, new();
        bool Update<T>(T item) where T : class, new();
        //查询服务
        IQueryable<T> GetQueryable<T>() where T : class, new();
        IList<T> GetAll<T>() where T : class, new();
        IList<T> GetAll<T>(IQueryable<T> query) where T : class, new();
        IList<T> GetPage<T>(int pageIndex, int pageSize, out int total) where T : class, new();
        IList<T> GetPage<T>(IQueryable<T> query,int pageIndex, int pageSize, out int total) where T : class, new();
        int GetCount<T>() where T : class, new();
        int GetCountByCriteria<T>(Expression<Func<T, bool>> whereLambda) where T : class, new();
        T GetByKey<T>(object key) where T : class, new();
        IList<T> GetByCriteria<T>(Expression<Func<T, bool>> whereLambda) where T : class, new();
        IList<T> GetByCriteria<T>(IQueryable<T> query, Expression<Func<T, bool>> whereLambda) where T : class, new();
        IList<T> GetPageByCriteria<T>(int pageIndex, int pageSize, out int total, Expression<Func<T, bool>> whereLambda) where T : class, new();
        IList<T> GetPageByCriteria<T>(IQueryable<T> query, int pageIndex, int pageSize, out int total, Expression<Func<T, bool>> whereLambda) where T : class, new();
    }
}
